package com.bolt.support.json.fastjson;

import com.alibaba.fastjson.parser.DefaultJSONParser;
import com.alibaba.fastjson.parser.deserializer.ObjectDeserializer;
import com.alibaba.fastjson.util.ParameterizedTypeImpl;
import com.bolt.convention.data.DefaultPageInfo;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

/**
 * Created by Administrator on 2019/9/10.
 */
public class PageDeserializer implements ObjectDeserializer {

    public static final PageDeserializer instance = new PageDeserializer();

    @Override
    public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
        if (type instanceof ParameterizedType) {
            ParameterizedType pType = (ParameterizedType) type;
            return (T) parser.parseObject(
                    new ParameterizedTypeImpl(
                            pType.getActualTypeArguments(),
                            pType.getOwnerType(), DefaultPageInfo.class),
                    fieldName);
        }
        return (T) parser.parseObject(DefaultPageInfo.class, fieldName);
    }

    @Override
    public int getFastMatchToken() {
        return 0;
    }
}

 